//
//  WBComposePictureView.swift
//  WB123
//
//  Created by xuyunde mac pro on 2017/7/9.
//  Copyright © 2017年 NSObjiect. All rights reserved.
//

import UIKit

private let WBComposePictureViewCellID = "WBComposePictureViewCellID"
class WBComposePictureView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        let cellMargin: CGFloat = 5
        let cellWH = (SCREENW - 20 - cellMargin * 2)/3
        
        let flowLayout = UICollectionViewFlowLayout()
        flowLayout.itemSize = CGSize(width: cellWH, height: cellWH)
        // 间距
        flowLayout.minimumLineSpacing = cellMargin
        flowLayout.minimumInteritemSpacing = cellMargin
        super.init(frame: frame, collectionViewLayout: flowLayout)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 设置界面
    private func setupUI(){
        backgroundColor = randomColor()
        dataSource = self
        register(WBComposePictureViewCell.self, forCellWithReuseIdentifier: WBComposePictureViewCellID)
    }
}
//MARK: - UICollectionViewDataSource
extension WBComposePictureView: UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 9
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WBComposePictureViewCellID, for: indexPath) as! WBComposePictureViewCell
        
        return cell
    }
}
